package com.controller;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/area")
public class AreaServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset = utf-8");
		String Up = req.getParameter("up");
		String Down = req.getParameter("down");
		String Height = req.getParameter("height");
		PrintWriter out = resp.getWriter();
		double result = 0.0;
		try {
result = (Double.parseDouble(Up)+Double.parseDouble(Down))*Double.parseDouble(Height)*0.5;
out.println("<html><body bgcolor='orange'>梯形的面积为"+result+"</body></html>");
		}catch(Exception e) {
out.println("<html><body bgcolor='pink'>您输入的格式有误,请重新输入!&nbsp;&nbsp;<a href='a.html'>重新输入</a></body></html>");
		}
	}	
}
